<?php
/**
 * Created by PhpStorm.
 * User: Shen
 * Date: 2015/3/24
 * Time: 20:44
 */
namespace Home\Controller;
use Think\Controller;
class AuthController extends CommonController {
    public function index(){
    	//获取权限
		$auth = D('RuleView');
        $count = $auth->count();
        $Page  = new \Library\Page($count,8);// $number为分页数
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% <li>%HEADER%</li>');
        $data['page'] = $Page->show();// 分页显示输出
        $data['auths'] =$auth->order('module_id')
                ->limit($Page->firstRow.','.$Page->listRows)
                ->select();
    	
    	$this->page = $data['page'];
    	$this->auths = $data['auths'];
    	// var_dump($data);die;
        $this->display();
    }

    // 添加权限
    public function add(){
    	$this->module = M('auth_module')->select();
    	$this->display();
    }

    // 添加权限操作
    public function addHandle(){
    	$rule = D('AuthRule');
    	if (!$rule->create()){
			$this->error($rule->getError());
		}else{
			$data = I();
	        //过滤方法必须为空,否则验证时会出错
			$data['condition']=I('post.condition','','');
			$rule->add($data)?$this->success("添加成功",__MODULE__."/Auth/"):$this->error("添加失败");
		}
    }

    // 删除操作
    public function del(){
    	$this->error("权限暂不提供删除功能！");
    	$rule = D('AuthRule');
    	if ($rule->delete(I('id'))) {
    		$this->success('删除成功！',__MODULE__."/Auth/");
    	}else{
    		$this->error('删除失败！');
    	}


    }


}